﻿using B.S.DataBase.MyProject.Domain.Procurements;
using B.S.DataBase.MyProject.Domain.Sales;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.SalesCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.SalesCommandHandler
{
    /// <summary>
    /// 查询退货通知单的详细信息处理方法
    /// </summary>
    public class Getreturn_notice_mainCommandHandler:IRequestHandler<Getreturn_notice_mainCommand,APIResult<List<return_notice_main>>>
    {
        /// <summary>
        /// 退货通知单仓储接口
        /// </summary>
        private readonly IBaseRepository<return_notice_main> rRepo;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="iRepo"></param>
        public Getreturn_notice_mainCommandHandler(IBaseRepository<return_notice_main> rRepo)
        {
            this.rRepo = rRepo;
        }

        public async Task<APIResult<List<return_notice_main>>> Handle(Getreturn_notice_mainCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<return_notice_main>> result = new APIResult<List<return_notice_main>>();
            var list = rRepo.GetAll().Result;
            if (request.document_code!=null)
            {
                list = list.Where(x => x.document_code == request.document_code);
            }
            list = list.OrderByDescending(x => x.notice_id);
            result.data = list.ToList();
            result.Code = APIEnum.成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.Count = list.Count();
            return await Task.FromResult(result);
        }
    }



}
